package nsq;
import java.util.concurrent.TimeoutException;

import com.github.brainlag.nsq.NSQConsumer;
import com.github.brainlag.nsq.exceptions.NSQException;
import com.github.brainlag.nsq.lookup.DefaultNSQLookup;
import com.github.brainlag.nsq.lookup.NSQLookup;


public class Consumer {
	public static void main(String[] args){
		NSQLookup lookup = new DefaultNSQLookup();
		lookup.addLookupAddress("localhost", 4161);
		NSQConsumer consumer = new NSQConsumer(lookup, "test", "dustin", (message) -> {
				String str =new String(message.getMessage());
		        System.out.println("received: " + str);            
		        //now mark the message as finished.
		        message.finished();
		        
		        //or you could requeue it, which indicates a failure and puts it back on the queue.
		        //message.requeue();
		});
		        
		consumer.start();
	}
}
